package cn.assumejson.springframework.aop.autoproxy;

import cn.assumejson.springframework.aop.Advisor;
import cn.assumejson.springframework.aop.aspectj.autoproxy.InstantiationModelAwarePointcutAdvisor;
import cn.assumejson.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
import cn.assumejson.springframework.aop.framework.autoproxy.AspectJPointcutAdvisor;

import java.util.List;

/**
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/6 11:09
 */
public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCreator {


    @Override
    protected boolean shouldSkip(Class<?> beanClass, String beanName) {
        // TODO: Consider optimization by caching the list of the aspect names
        List<Advisor> candidateAdvisors = findCandidateAdvisors();
        for (Advisor advisor : candidateAdvisors) {
            if (advisor instanceof InstantiationModelAwarePointcutAdvisor &&
                    ((InstantiationModelAwarePointcutAdvisor) advisor).getAspectName().equals(beanName)) {
                return true;
            }
        }
        return super.shouldSkip(beanClass, beanName);
    }
}
